<?php


namespace App\Http\Controllers\api\access;


use App\Http\Controllers\api\base\BaseController;
use App\Http\Resources\access\AccessResource;
use App\Models\access\AccessVote;
use Illuminate\Http\Request;

class AccessVoteController extends BaseController
{
    public function lists(Request $request)
    {
        $keyword = $request->keyword;
        $page_size = $request->page_size;
        $data = AccessVote::lists($this->user_id,$keyword,$page_size);
        return success(new AccessResource($data));
    }

    public function leaderDetail(Request $request)
    {
        $access_id = $request->access_id;
        $user_id = $this->user_id;
        $data = AccessVote::leader_vote_detail($user_id,$access_id);
        if(isset($data['code'])){
            return error($data['msg']);
        }
        return success($data);
    }

    public function userDetail(Request $request)
    {
        $access_id = $request->access_id;
        $user_id = $this->user_id;
        $data = AccessVote::user_vote_detail($user_id,$access_id);
        if(!$data){
            return error('考核失败');
        }
        return success($data);
    }

    public function voteCommit(Request $request)
    {
        $vote = $request->vote;
        $access_id = $request->access_id;
        $data = AccessVote::voteCommit($this->user_id,$access_id,$vote);
        if(isset($data['code'])){
            return error($data['msg']);
        }
        return success();
    }
}